module.exports = function(success, error) {
  // if(typeof error !== 'function') {
  //   console.error('error参数必须是一个函数');
  // }

  const mongoose = require('mongoose');


  mongoose.connect('mongodb://localhost:27017/control-book');
  // mongoose.connect('mongodb://localhost:27017/Categories');
  // mongoose.connect('mongodb://localhost:27017/Users');
  // mongoose.connect('mongodb://localhost:27017/Likes');

  mongoose.connection.once('open', () => {
    console.log('数据库连接成功')
    success("数据库连接成功")
  })

  // mongoose.connection.on('error', () => {
  //   error("数据库连接失败")
  // });

  mongoose.connection.on('close', () => {
    console.log('数据库连接断开')
  });

}